home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / disk-man / mtools-3.000 / mtools-3 / mtools-3.0 / devices.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-08  |  2.8 KB  |  149 lines

  1. #ifdef linux
  2.  
  3. #include <sys/types.h>
  4. #include <linux/fd.h>
  5. #include <linux/fdreg.h>
  6. #include <linux/major.h>
  7. #include <linux/fs.h>
  8.  
  9.  
  10. typedef struct floppy_raw_cmd RawRequest_t;
  11.  
  12.  
  13. static inline void RR_INIT(struct floppy_raw_cmd *request)
  14. {
  15.     request->data = 0;
  16.     request->length = 0;
  17.     request->cmd_count = 9;
  18.     request->flags = FD_RAW_INTR | FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK
  19. #ifdef FD_RAW_SOFTFAILUE
  20.         | FD_RAW_SOFTFAILURE | FD_RAW_STOP_IF_FAILURE
  21. #endif
  22.         ;
  23.     request->cmd[1] = 0;
  24.     request->cmd[6] = 0;
  25.     request->cmd[7] = 0x1b;
  26.     request->cmd[8] = 0xff;
  27.     request->reply_count = 0;
  28. }
  29.  
  30.  
  31. static inline void RR_SETRATE(struct floppy_raw_cmd *request, int rate)
  32. {
  33.     request->rate = rate;
  34. }
  35.  
  36. static inline void RR_SETDRIVE(struct floppy_raw_cmd *request, int drive)
  37. {
  38.     request->cmd[1] = (request->cmd[1] & ~3) | (drive & 3);
  39. }
  40.  
  41. static inline void RR_SETTRACK(struct floppy_raw_cmd *request, int track)
  42. {
  43.     request->cmd[2] = track;
  44. }
  45.  
  46. static inline void RR_SETPTRACK(struct floppy_raw_cmd *request, int track)
  47.     {
  48.     request->track = track;
  49. }
  50.  
  51. static inline void RR_SETHEAD(struct floppy_raw_cmd *request, int head)
  52. {
  53.     if(head)
  54.         request->cmd[1] |= 4;
  55.     else
  56.         request->cmd[1] &= ~4;
  57.     request->cmd[3] = head;
  58. }
  59.  
  60. static inline void RR_SETSECTOR(struct floppy_raw_cmd *request, int sector)
  61. {
  62.     request->cmd[4] = sector;
  63. }
  64.  
  65. static inline void RR_SETSIZECODE(struct floppy_raw_cmd *request, int sizecode)
  66. {
  67.     request->cmd[5] = sizecode;
  68.     request->length += 128 << sizecode;
  69. }
  70.  
  71. #if 0
  72. static inline void RR_SETEND(struct floppy_raw_cmd *request, int end)
  73. {
  74.     request->cmd[6] = end;
  75. }
  76. #endif
  77.  
  78. static inline void RR_SETDIRECTION(struct floppy_raw_cmd *request, int direction)
  79. {
  80.  
  81.     if(direction == MT_READ) {
  82.         request->flags |= FD_RAW_READ;
  83.         request->cmd[0] = FD_READ;
  84.     } else {
  85.         request->flags |= FD_RAW_WRITE;
  86.         request->cmd[0] = FD_WRITE;
  87.     }
  88. }
  89.  
  90.  
  91. static inline void RR_SETDATA(struct floppy_raw_cmd *request, caddr_t data)
  92. {
  93.     request->data = data;
  94. }
  95.  
  96.  
  97. #if 0
  98. static inline void RR_SETLENGTH(struct floppy_raw_cmd *request, int length)
  99. {
  100.     request->length += length;
  101. }
  102. #endif
  103.  
  104. static inline void RR_SETCONT(struct floppy_raw_cmd *request)
  105. {
  106. #ifdef FD_RAW_MORE
  107.     request->flags |= FD_RAW_MORE;
  108. #endif
  109. }
  110.  
  111.  
  112. static inline int RR_SIZECODE(struct floppy_raw_cmd *request)
  113. {
  114.     return request->cmd[5];
  115. }
  116.  
  117.  
  118.  
  119. static inline int RR_TRACK(struct floppy_raw_cmd *request)
  120. {
  121.     return request->cmd[2];
  122. }
  123.  
  124.  
  125. static inline int GET_DRIVE(int fd)
  126. {
  127.     struct stat statbuf;
  128.  
  129.     if (fstat(fd, &statbuf) < 0 ){
  130.         perror("stat");
  131.         return -1;
  132.     }
  133.       
  134.     if (!S_ISBLK(statbuf.st_mode) ||
  135.         MAJOR(statbuf.st_rdev) != FLOPPY_MAJOR)
  136.         return -1;
  137.     
  138.     return MINOR( statbuf.st_rdev );
  139. }
  140.  
  141.  
  142.  
  143. /* void print_message(RawRequest_t *raw_cmd,char *message);*/
  144. int send_one_cmd(int fd, RawRequest_t *raw_cmd, char *message);
  145. int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print);
  146.  
  147.  
  148. #endif
  149.